package cn.cdeden.knowledge.dubbo;

import cn.cdeden.common.core.utils.MapstructUtils;
import cn.cdeden.knowledge.api.domain.RemoteCalendarTypeService;
import cn.cdeden.knowledge.api.domain.RemoteResourceFollowService;
import cn.cdeden.knowledge.api.domain.vo.RemoteCalendarTypeVo;
import cn.cdeden.knowledge.domain.SysCalendarType;
import cn.cdeden.knowledge.domain.SysResourceFollow;
import cn.cdeden.knowledge.domain.SysResourceType;
import cn.cdeden.knowledge.service.SysCalendarTypeService;
import cn.cdeden.knowledge.service.SysResourceFollowService;
import cn.cdeden.knowledge.service.SysResourceTypeService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.RequiredArgsConstructor;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Set;

@RequiredArgsConstructor
@Service
@DubboService
public class RemoteCalenderTypeServiceImpl implements RemoteCalendarTypeService {

    private final SysCalendarTypeService sysCalendarTypeService;

    @Override
    public boolean save(RemoteCalendarTypeVo sysCalendarType) {
        return sysCalendarTypeService.save(MapstructUtils.convert(sysCalendarType, SysCalendarType.class));
    }

    @Override
    public boolean removeById(Long sysCalendarTypeId) {
        return sysCalendarTypeService.removeById(sysCalendarTypeId);
    }

    @Override
    public boolean updateById(RemoteCalendarTypeVo sysCalendarType) {
        return sysCalendarTypeService.updateById(MapstructUtils.convert(sysCalendarType, SysCalendarType.class));
    }

    @Override
    public List<RemoteCalendarTypeVo> listByValue(String value) {
        List<SysCalendarType> list = sysCalendarTypeService.list(new QueryWrapper<SysCalendarType>().eq("value", value));
        return MapstructUtils.convert(list,RemoteCalendarTypeVo.class);
    }

    @Override
    public List<RemoteCalendarTypeVo> getAllByLikeName(String name) {
        QueryWrapper<SysCalendarType> sysCalendarTypeQueryWrapper = new QueryWrapper<>();
        if (name != null && name != "") {
            sysCalendarTypeQueryWrapper.like("name",name);
        }
        List<SysCalendarType> list = sysCalendarTypeService.list(sysCalendarTypeQueryWrapper);
        return MapstructUtils.convert(list,RemoteCalendarTypeVo.class);
    }

    @Override
    public List<RemoteCalendarTypeVo> listByEqName(String name) {
        List<SysCalendarType> list = sysCalendarTypeService.list(new QueryWrapper<SysCalendarType>().eq("name",name));
        return MapstructUtils.convert(list,RemoteCalendarTypeVo.class);
    }

    @Override
    public List<RemoteCalendarTypeVo> listByUpdate(RemoteCalendarTypeVo sysCalendarType) {
        List<SysCalendarType> list = sysCalendarTypeService.list(new QueryWrapper<SysCalendarType>()
            .eq("name", sysCalendarType.getName())
            .or()
            .eq("value", sysCalendarType.getValue())
            .ne("id", sysCalendarType.getId()));
        return MapstructUtils.convert(list,RemoteCalendarTypeVo.class);
    }
}
